﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kairos.Models;
using System.Data.Entity.Infrastructure;

namespace Kairos.Controllers
{
    public class Meta1Controller : Controller
    {
        private myContext db = new myContext();

        //
        // GET: /Meta1/

        [AccessControl(Roles.Administrator)]
        public ActionResult Index()
        {
            return View(db.MetaDatas1.ToList());
        }

        //
        // GET: /Meta1/Details/5

        [AccessControl(Roles.Administrator)]
        public ActionResult Details(int id = 0)
        {
            MetaData1 metadata1 = db.MetaDatas1.Find(id);
            if (metadata1 == null)
            {
                return HttpNotFound();
            }
            return View(metadata1);
        }

        //
        // GET: /Meta1/Create

        [AccessControl(Roles.Administrator)]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Meta1/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        [AccessControl(Roles.Administrator)]
        public ActionResult Create(MetaData1 metadata1)
        {
            if (ModelState.IsValid)
            {
                db.MetaDatas1.Add(metadata1);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(metadata1);
        }

        //
        // GET: /Meta1/Edit/5

        [AccessControl(Roles.Administrator)]
        public ActionResult Edit(int id = 0)
        {
            MetaData1 metadata1 = db.MetaDatas1.Find(id);
            if (metadata1 == null)
            {
                return HttpNotFound();
            }
            return View(metadata1);
        }

        //
        // POST: /Meta1/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        [AccessControl(Roles.Administrator)]
        public ActionResult Edit(MetaData1 metadata1)
        {
            if (ModelState.IsValid)
            {
                db.Entry(metadata1).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(metadata1);
        }

        //
        // GET: /Meta1/Delete/5

        [AccessControl(Roles.Administrator)]
        public ActionResult Delete(int id = 0, Reason reason = Reason.Standard)
        {
            MetaData1 metadata1 = db.MetaDatas1.Find(id);
            if (metadata1 == null)
            {
                return HttpNotFound();
            }

            ViewBag.Reason = reason;

            return View(metadata1);
        }

        //
        // POST: /Meta1/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        [AccessControl(Roles.Administrator)]
        public ActionResult DeleteConfirmed(int id)
        {
            MetaData1 metadata1 = db.MetaDatas1.Find(id);
            db.MetaDatas1.Remove(metadata1);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException dbUpdateException)
            {
                if (ExceptionHandling.HandlesSqlExceptionNumber547(dbUpdateException))
                    return RedirectToAction("Delete", new { id = id, reason = Reason.Delete });
                else
                    throw;
            }

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}